home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 176-200 / disk_183 / mklib / text.c < prev   
C/C++ Source or Header  |  1992-05-06  |  14KB  |  452 lines

  1. /*
  2.     Mklib 1.0 - a source file generator for Amiga shared libraries
  3.     Compiled with Manx v3.6a small code model/16 bit int. (see makefile)
  4.  
  5.     copyright 1988 Edwin Hoogerbeets
  6.  
  7.     This software and the files it produces are freely redistributable
  8.     as long there is no charge beyond reasonable copy fees and as long
  9.     as this notice stays intact.
  10.  
  11.     Thanks to Jimm Mackraz for Elib on Fish 87, from which much of this
  12.     program is lifted. Also thanks to Neil Katin for his mylib.asm upon
  13.  
  14. */
  15. #include <stdio.h>
  16. #include <ctype.h>
  17. #include <edlib.h>
  18.  
  19. char *makeheader[] = {
  20.     "# This makefile was generated with mklib",
  21.     "# copyright 1988 Edwin Hoogerbeets",
  22.     "#",
  23.     "# This software is freely redistributable as long as there is no charge",
  24.     "# beyond resonable copy fees and as long as this notice stays intact.",
  25.     "#",
  26.     "# Thanks to Jimm Mackraz for Elib on Fish 87, from which much of this",
  27.     "# program is lifted. Also thanks to Neil Katin for his mylib.asm upon",
  28.     "# which elib is based.",
  29.     "",
  30.     "CFLAGS=-T",
  31.     "",
  32.     NULL
  33. };
  34.  
  35. char *makefooter[] = {
  36.     "        ln $(OBJS) -lc -o $@",
  37.     "",
  38.     "#yourprog: yourprog.o link.o",
  39.     "#       ln yourprog.o link.o -lc -o $@",
  40.     NULL
  41. };
  42.  
  43. char *facemid[] = {
  44.     "",
  45.     "        public  _geta4",
  46.     "",
  47.     "myopen:",
  48.     "        setup",
  49.     "        push a6",
  50.     "        jsr     _myOpen",
  51.     "        restore 4",
  52.     "",
  53.     "myclose:",
  54.     "        setup",
  55.     "        push a6",
  56.     "        jsr     _myClose",
  57.     "        restore 4",
  58.     "",
  59.     "myexpunge:",
  60.     "        setup",
  61.     "        push a6",
  62.     "        jsr     _myExpunge",
  63.     "        restore 4",
  64.     "",
  65.     NULL
  66. };
  67.  
  68. char *asmheader[] = {
  69.     "; This file was generated with mklib",
  70.     "; copyright 1988 Edwin Hoogerbeets",
  71.     ";",
  72.     "; This software is freely redistributable as long as there is no charge",
  73.     "; beyond resonable copy fees and as long as this notice stays intact.",
  74.     ";",
  75.     "; Thanks to Jimm Mackraz for Elib on Fish 87, from which much of this",
  76.     "; program is lifted. Also thanks to Neil Katin for his mylib.asm upon",
  77.     "; which elib is based.",
  78.     ";",
  79.     "",
  80.     NULL
  81. };
  82.  
  83. char *cheader[] = {
  84.     "/*",
  85.     "   This file was generated with mklib",
  86.     "   copyright 1988 Edwin Hoogerbeets",
  87.     "",
  88.     "   This software is freely redistributable as long as there is no charge",
  89.     "   beyond resonable copy fees and as long as this notice stays intact.",
  90.     "",
  91.     "   Thanks to Jimm Mackraz for Elib on Fish 87, from which much of this",
  92.     "   program is lifted. Also thanks to Neil Katin for his mylib.asm upon",
  93.     "   which elib is based.",
  94.     "*/",
  95.     "",
  96.     NULL
  97. };
  98.  
  99. char *startupcode[] = {
  100.     ";:ts=8",
  101.     "; Copyright (C) 1986 by Manx Software Systems, Inc.",
  102.     ";",
  103.     "",
  104.     "; ***   But FUNKIFIED by jimm ***",
  105.     ";       library base in D0",
  106.     ";       segment list in A0",
  107.     ";       execbase in A6",
  108.     "",
  109.     ";       Initial startup routine for Aztec C.",
  110.     "",
  111.     ";       NOTE: code down to \"start\" must be placed at beginning of",
  112.     ";               all programs linked with Aztec Linker using small",
  113.     ";               code or small data.",
  114.     "",
  115.     "",
  116.     "a4save  dc.l    0",
  117.     "",
  118.     "        public  .begin                  ; just to resolve label",
  119.     ".begin",
  120.     "        public  _funkyInit",
  121.     "_funkyInit:",
  122.     "",
  123.     "        near    code",
  124.     "",
  125.     "        movem.l d0/d2/d3/d4-d7/a2-a6,-(sp)",
  126.     "",
  127.     "        ; FUNKY use a0, not a1 for segment list",
  128.     "        move.l  a0,a4                   ;BPTR to code seg",
  129.     "        add.l   a4,a4",
  130.     "        add.l   a4,a4                   ;now real address of code seg",
  131.     "",
  132.     "        move.l  (a4),a4                 ;indirect to get data segment BPTR",
  133.     "        add.l   a4,a4                   ;convert to real pointer",
  134.     "        add.l   a4,a4                   ;real address of data seg link field",
  135.     "",
  136.     "        ; same as crt0.a68",
  137.     "        add.l   #32766+4,a4             ;bias appropriately (+4 is for link)",
  138.     "        lea     __H1_end,a1",
  139.     "        lea     __H2_org,a2",
  140.     "        cmp.l   a1,a2                   ;check if BSS and DATA together",
  141.     "        bne     start                   ;no, don't have to clear",
  142.     "        move.w  #((__H2_end-__H2_org)/4)-1,d1",
  143.     "        bmi     start                   ;skip if no bss",
  144.     "        move.l  #0,d2",
  145.     "loop",
  146.     "        move.l  d2,(a1)+                ;clear out memory",
  147.     "        dbra    d1,loop",
  148.     "",
  149.     "start",
  150.     "        lea     a4save,a1               ;get address of a4save",
  151.     "        move.l  a4,(a1)                 ;save a4",
  152.     ";       FUNKY",
  153.     ";       move.l  sp,__savsp              ;save stack pointer (can't fexec)",
  154.     ";       move.l  4,a6                    ;get Exec's library base pointer",
  155.     "        move.l  a6,_SysBase             ;put where we can get it",
  156.     "",
  157.     "        movem.l d0/a0,-(sp)             ; pass base and seglist",
  158.     "        jsr     _funkymain              ; FUNKY",
  159.     "        addq.l  #8,sp                   ;pop args to  funkymain()",
  160.     "                                        ; can pop better (?)",
  161.     "",
  162.     "        movem.l (sp)+,d0/d2/d3/d4-d7/a2-a6",
  163.     "        rts                             ;and return",
  164.     "",
  165.     "        public  _geta4",
  166.     "_geta4:",
  167.     "        move.l  a4save,a4",
  168.     "        rts",
  169.     "",
  170.     "        dseg",
  171.     "",
  172.     "",
  173.     "_SysBase        dc.l    0",
  174.     "",
  175.     "        public  _funkymain",
  176.     "        public  _SysBase",
  177.     "        public  __H1_end,__H2_org,__H2_end",
  178.     "",
  179.     "        end",
  180.     NULL
  181. };
  182.  
  183. char *rtag[] = {
  184.     ";       rtag.asm -- romtag",
  185.     "",
  186.     "         include 'exec/types.i'",
  187.     "         include 'exec/resident.i'",
  188.     "         include 'exec/nodes.i'",
  189.     "         include 'exec/libraries.i'",
  190.     "",
  191.     "MYVERSION       equ     1",
  192.     "MYPRI           equ     0",
  193.     "",
  194.     "         cseg    ; romtag must be in first hunk",
  195.     "",
  196.     "         public  _myname",
  197.     "         public  _myid",
  198.     "         public  _myInitTab",
  199.     "",
  200.     "         ds      0",
  201.     "         public  _myRomTag",
  202.     "_myRomTag:",
  203.     "         dc.w    RTC_MATCHWORD",
  204.     "         dc.l    _myRomTag",
  205.     "         dc.l    endtag",
  206.     "         dc.b    RTF_AUTOINIT",
  207.     "         dc.b    MYVERSION",
  208.     "         dc.b    NT_LIBRARY",
  209.     "         dc.b    MYPRI",
  210.     "         dc.l    _myname",
  211.     "         dc.l    _myid",
  212.     "         dc.l    _myInitTab",
  213.     "endtag:",
  214.     "",
  215.     "         end",
  216.     NULL
  217. };
  218.  
  219. char *mandatory[] = {
  220.     "/* created by jim mackraz using mylib.asm by neil katin",
  221.     " * may be used and distributed providing this comment block",
  222.     " * is retained in the source code",
  223.     " */",
  224.     "#include <stdio.h>",
  225.     "#include \"lib.h\"",
  226.     "",
  227.     "extern  PFL     libfunctab[];   /* my function table (libface.asm)              */",
  228.     "extern  LONG    funkyInit();    /* hacked up version of Aztec crt0.a68  */",
  229.     "",
  230.     "LONG    myExpunge();",
  231.     "",
  232.     "struct InitTable myInitTab =  {",
  233.     "        sizeof (struct MyBase),",
  234.     "        libfunctab,",
  235.     "        NULL,                                   /* will initialize my data in funkymain()       */",
  236.     "        funkyInit",
  237.     "};",
  238.     "",
  239.     "#define MYREVISION      0               /* would be nice to auto-increment this         */",
  240.     "",
  241.     "extern char myname[];",
  242.     "extern char myid[];",
  243.     "",
  244.     "extern struct Resident  myRomTag;",
  245.     "",
  246.     "/*",
  247.     " * this function is my C-language library initRoutine.  It is called",
  248.     " * by funkyInit() after register saves and small model initialization is",
  249.     " * done.",
  250.     " */",
  251.     "",
  252.     "LONG",
  253.     "funkymain(libbase, seglist)",
  254.     "struct  MyBase  *libbase;",
  255.     "ULONG                   seglist;",
  256.     "{",
  257.     "        register        struct MyBase *base;",
  258.     "",
  259.     "        /* cookie       */",
  260.     "        base = libbase;",
  261.     "        base->mb_Cookie = 0xDEAD1234;   /* debug kind of stuff                          */",
  262.     "        base->mb_SegList = seglist;",
  263.     "",
  264.     "        /* init. library structure (since I don't do automatic data init.)      */",
  265.     "        base->mb_Lib.lib_Node.ln_Type = NT_LIBRARY;",
  266.     "        base->mb_Lib.lib_Node.ln_Name = (char *) myname;",
  267.     "        base->mb_Lib.lib_Flags = LIBF_SUMUSED | LIBF_CHANGED;",
  268.     "        base->mb_Lib.lib_Version = myRomTag.rt_Version;",
  269.     "        base->mb_Lib.lib_Revision = MYREVISION;",
  270.     "        base->mb_Lib.lib_IdString = (APTR) myid;",
  271.     "",
  272.     "        /* ----- do your own initialization here -----  */",
  273.     "}",
  274.     "",
  275.     "LONG",
  276.     "myOpen(base)    /* baseptr in A6, version in D0 */",
  277.     "struct  MyBase *base;",
  278.     "{",
  279.     "        /* mark us as having another customer                                   */",
  280.     "        base->mb_Lib.lib_OpenCnt++;",
  281.     "",
  282.     "        /* prevent delayed expunges (standard procedure)                */",
  283.     "        base->mb_Lib.lib_Flags &= ~LIBF_DELEXP;",
  284.     "",
  285.     "        return ((LONG) base);",
  286.     "}",
  287.     "",
  288.     "LONG",
  289.     "myClose(base)",
  290.     "struct  MyBase *base;",
  291.     "{",
  292.     "        LONG    retval = 0;",
  293.     "",
  294.     "        if ((--base->mb_Lib.lib_OpenCnt == 0) &&",
  295.     "                        (base->mb_Lib.lib_Flags & LIBF_DELEXP))",
  296.     "        {",
  297.     "                /* no more people have me open,",
  298.     "                 * and I have a delayed expunge pending",
  299.     "                 */",
  300.     "                retval = myExpunge(); /* return segment list    */",
  301.     "        }",
  302.     "",
  303.     "        return (retval);",
  304.     "}",
  305.     "",
  306.     "LONG",
  307.     "myExpunge(base)",
  308.     "struct  MyBase  *base;",
  309.     "{",
  310.     "        ULONG                   seglist = 0;",
  311.     "        LONG                    libsize;",
  312.     "",
  313.     "        if (base->mb_Lib.lib_OpenCnt == 0)",
  314.     "        {",
  315.     "                /* really expunge: remove libbase and freemem   */",
  316.     "",
  317.     "                seglist = base->mb_SegList;",
  318.     "",
  319.     "                Remove(base);",
  320.     "",
  321.     "                libsize = base->mb_Lib.lib_NegSize + base->mb_Lib.lib_PosSize;",
  322.     "                FreeMem((char *) base - base->mb_Lib.lib_NegSize, (LONG) libsize);",
  323.     "        }",
  324.     "        else",
  325.     "        {",
  326.     "                base->mb_Lib.lib_Flags &= LIBF_DELEXP;",
  327.     "        }",
  328.     "",
  329.     "",
  330.     "        /* return NULL or real seglist */",
  331.     "        return ((LONG) seglist);",
  332.     "}",
  333.     "",
  334.     NULL
  335. };
  336.  
  337.  
  338. char *faceheader[] = {
  339.     "        include 'exec/types.i'",
  340.     "",
  341.     "setup   macro",
  342.     "        movem.l d2/d3/d4-d7/a2-a6,-(sp)",
  343.     "        jsr     _geta4",
  344.     "        endm",
  345.     "",
  346.     "push    macro",
  347.     "        move.l  \\1,-(sp)",
  348.     "        endm",
  349.     "",
  350.     "fix     macro",
  351.     "        ifc     '\\1',''",
  352.     "                mexit",
  353.     "        endc",
  354.     "        ifle    \\1-8",
  355.     "                addq.l  #\\1,sp",
  356.     "        endc",
  357.     "        ifgt    \\1-8",
  358.     "                lea     \\1(sp),sp",
  359.     "        endc",
  360.     "        endm",
  361.     "",
  362.     "restore macro",
  363.     "        fix     \\1",
  364.     "        movem.l (sp)+,d2/d3/d4-d7/a2-a6",
  365.     "        rts",
  366.     "        endm",
  367.     "",
  368.     "        dseg",
  369.     "",
  370.     "        public  _libfunctab",
  371.     "_libfunctab:",
  372.     "        dc.l    myopen",
  373.     "        dc.l    myclose",
  374.     "        dc.l    myexpunge",
  375.     "        dc.l    $0000",
  376.     NULL
  377. };
  378.  
  379. char *incbody[] = {
  380.     "#include <exec/types.h>",
  381.     "#include <exec/nodes.h>",
  382.     "#include <exec/resident.h>",
  383.     "#include <exec/libraries.h>",
  384.     "",
  385.     "#include <functions.h>",
  386.     "",
  387.     "typedef LONG (*PFL)();      /* pointer to function returning 32-bit int */",
  388.     "",
  389.     "/* library initialization table, used for AUTOINIT libraries                    */",
  390.     "struct InitTable {",
  391.     "    ULONG   it_DataSize;    /* library data space size          */",
  392.     "    PFL     *it_FuncTable;  /* table of entry points            */",
  393.     "    APTR    it_DataInit;    /* table of data initializers       */",
  394.     "    PFL     it_InitFunc;    /* initialization function to run   */",
  395.     "};",
  396.     "",
  397.     "struct MyBase {",
  398.     "    struct  Library mb_Lib;",
  399.     "    ULONG   mb_Cookie;      /* looks good                       */",
  400.     "    ULONG   mb_SegList;",
  401.     "    ULONG   mb_Flags;",
  402.     "    APTR    mb_ExecBase;    /* pointer to exec base             */",
  403.     "    APTR    mb_A4;          /* proper value of A4 for aztec small model */",
  404.     "};",
  405.     NULL
  406. };
  407.  
  408. char *linkhead[] = {
  409.     "        include 'exec/types.i'",
  410.     "        include 'exec/libraries.i'",
  411.     "",
  412.     "        LIBINIT",
  413.     NULL
  414. };
  415.  
  416. char *link2[] = {
  417.     "",
  418.     "store   macro",
  419.     "        movem.l d2-d7/a2-a5,safekeep",
  420.     "        endm",
  421.     "",
  422.     "retrieve macro",
  423.     "        movem.l safekeep,d2-d7/a2-a5",
  424.     "        endm",
  425.     "",
  426.     "        dseg",
  427.     "",
  428.     "safekeep:",
  429.     "        dcb.l 14     ; reserve some space for temporary register storage",
  430.     "",
  431.     "        cseg",
  432.     "",
  433.     "        ; --- xref from application",
  434.     "        public  _libbase",
  435.     "",
  436.     "        ; --- xdef for application\n",
  437.     NULL
  438. };
  439.  
  440. char *face2[] = {
  441.     "        dc.l    $ffffffff",
  442.     "",
  443.     "        cseg",
  444.     "",
  445.     "        ;--- library functions",
  446.     "        public  _myOpen",
  447.     "        public  _myClose",
  448.     "        public  _myExpunge",
  449.     NULL
  450. };
  451.  
  452.